
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 

\documentclass[12pt,a4paper]{article}
\usepackage{amssymb}
\usepackage{xltxtra,fontspec,xunicode}
\usepackage{fancyhdr}
\usepackage{hyperref}
\baselineskip 9pt
\hypersetup{ %CJKbookmarks=true,
  bookmarksnumbered=true,
  bookmarksopen=true,
  colorlinks=true,
  citecolor=black,
  linkcolor=black,
  anchorcolor=black,
  urlcolor=black,
  plainpages=false,
  pdfstartview=FitH}

\usepackage[%showframe,
top=4cm, bottom=4.4cm,
headsep=0.6cm,
headheight=0.6cm, 
footnotesep=0.8cm,
footskip=1.4cm,
hmargin=3.2cm
% twosideshift=0 pt,
]{geometry}

\usepackage{hyperref}
\pagestyle{fancy}

\newcommand{\bnf}{$::=$}
\newcommand{\deli}{$|$}
% \usepackage{listing}
\begin{document}
\title{Language Specification}
\author{Compiler Course}
\date{\today}
\maketitle


% \tableofcontents{}

\section{Notation}
\label{sec:notation}

In the rules given below, we will use following notaions.

\begin{description}
\item[Alternative] ``a \deli{} b'' means \textit{a} or \textit{b}
\item[Optional] ``[a]'' stands for an optional \textit{a}. It is equal
  to ``a | $\varepsilon$''($\varepsilon$ stands for empty sequence) 
\item[Repetition] ``\{a\}'' stands for ``$\varepsilon$ | a | aa | aaa | \ldots{}''
\end{description}

\textit{Italics} means nonterminals and \textbf{Bolds} means
terminals. 


\section{Lexical Rules}
\label{sec:lex}


\begin{figure}[!htp]

  \begin{tabular}{lll}
    \textit{letter} & \bnf{} & a | b | \ldots{} | z | A | B |
    \ldots{} | Z \\
    \textit{digit} & \bnf{} & 0 | 1 | \ldots{} | 9 \\
    \textbf{id} & \bnf{} & \textit{letter}\{\textit{letter}|\textit{digit}|\_\} \\
    \textbf{integer} & \bnf{} & \textit{digit}\{\textit{digit}\} \\
    \textbf{char} & \bnf{} &  'ch' | '$\backslash$n' | '$\backslash$0'
    (\textit{ch} means any printable ASCII character)\\
    \textbf{string} & \bnf{} & ``\{ch\}'' \\
    \textbf{comment} &  & any sequence starts with ``/*'' and
    ends with ``*/''\\ 
    & & (the sequence should not contain ``*/'')
    
  \end{tabular}
  \label{fig:lex}
\end{figure}

\section{Syntatic Rules}
\label{sec:syntax}

\subsection{Grammar}
\label{sec:grammar}
See Fig \ref{fig:syntax}

\begin{figure}[!htp]

  \begin{tabular}{lll}
    \textit{prog} & \bnf{}  & \{\textit{struc\_decl}``;''|\textit{func}\} \\

    \textit{struc\_decl} & \bnf{} & \textbf{structure} \textbf{id} ``\{''
    \textit{var\_decl} ``\}'' \\

    \textit{var\_decl} & \bnf{}  &
    \textit{type}[*] \textit{var}\{``,''\textit{var}\} ``;'' \\
    
    \textit{var} & \bnf{} & \textbf{id}[ ``[''\textbf{integer}``]'' ]
    \\

    \textit{type} & \bnf{} & \textbf{char} | \textbf{int} | \textbf{void} | \textbf{structure} \textbf{id} \\

    \textit{func} & \bnf{} & \textit{type} \textbf{id} ``('' [\textit{type
      var\_decl}\{``,''\textit{var\_decl} ``;''\}] ``)'' ``\{'' \textit{stmt}
    ``\}'' \\

    \textit{stmt} & \bnf{} & \textbf{if} ``('' \textit{expr} ``)'' \textit{stmt}
    [\textbf{else} \textit{stmt}] \\
                  & \deli{}& \textbf{while} ``('' \textit{expr} ``)''
                  \textit{stmt} \\
                  & \deli{}& \textbf{for} ``(''
                  \textit{assign}``;''\textit{expr}``;''\textit{assign} ``)''
                  \textit{stmt} \\
                  & \deli{}& \textbf{return} [\textit{expr}] ``;'' \\
                  & \deli{}&\textbf{id} ``(''[\textit{expr}\{``,''\textit{expr}\}] ``)''
                  ``;'' \\
                  & \deli{}& ``\{'' \{\textit{stmt}\} ``\}'' \\
                  & \deli{}& ``;'' \\

   \textit{assign}& \bnf{} & \textbf{id}[``[''\textit{expr}``]''] ``=''
   \textit{expr} \\

   \textit{expr} & \bnf{} & ``-'' \textit{expr} \\
                 &\deli{} & ``!'' \textit{expr} \\
                 &\deli{} & \textit{expr} \textit{binop} \textit{expr} \\
                 &\deli{} & \textit{expr} \textit{relop} \textit{expr} \\
                 &\deli{} & \textit{expr} \textit{logicop} \textit{expr} \\
                 &\deli{} & \textbf{integer} | \textbf{char} | \textbf{string} \\
                 &\deli{} & \textbf{id}[``('' [\textit{expr}\{``,''\textit{expr}]\} ``)'' | ``['' \textit{expr} ``]'' ] \\
                 &\deli{} & ``('' \textit{expr} ``)'' \\

   \textit{binop} & \bnf{} & $+$ | $-$ | $*$ | $/$ \\
   \textit{relop} & \bnf{} & $==$ | $!=$ | $>$ | $>=$ | $<$ | $<=$ \\
   \textit{logicop} & \bnf{} & \&\& | $||$ \\
  \end{tabular}
  \caption{syntax}
  \label{fig:syntax}
\end{figure}



\subsection{Operator Associativities and Precedences}
\label{sec:oper-assoc-prec}
The following table describes associativities and precendences of all the
operators. The higher operator has a higher precendence.

\begin{figure}[!htp]
  \begin{tabular}{ll}
    \textbf{Operator} & \textbf{ Associativity} \\
    \hline{}
    $!$,$-$(unary) & right to left \\
    $*$,$/$        & left to right \\
    $+,-$(binary)  & left to right \\
    $>$,$>=$,$<$,$<=$ & left to right \\
    $==$,$!=$ & left to right \\
    \&\& & left to right \\
    $||$ & left to right \\    
  \end{tabular}
  \label{fig:op}
\end{figure}



\section{Typing Rules}
\label{sec:typing-rules}



\section{Example}
\label{sec:example}

\begin{verbatim}

\end{verbatim}






\end{document}